package com.itheima.myfile.test3;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class ServerDemo {
    public static void main(String[] args) throws IOException {
        //创建服务器
        ServerSocket ss = new ServerSocket(10000);
        //创建字节缓冲读取到指定文件中
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("day12_file&IOstream\\Server\\1.jpg"));
        //接收客服端传来的信息
        Socket accept = ss.accept();
        InputStream is = accept.getInputStream();
        //创建字节流进行读取
        BufferedInputStream bis = new BufferedInputStream(accept.getInputStream());
        int b;
        while((b=bis.read())!=-1){
            bos.write(b);
        }

        //给客户端反馈
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(accept.getOutputStream()));
        bw.write("上传成功");
        bw.newLine();
        bw.flush();
        bw.close();
        ss.close();
    }
}
